<template>
  <div>
    <el-row>
      <el-col :span=8>
        <div>
          <chessboard :onPromotion="promote" :free="ifFree" :orientation="boardColor" @onMove="getInfo"
                      :fen="currentFen" :style="{opacity: isBoss ? 0.05 : 1 }"/>
        </div>
      </el-col>
      <el-col :span=16 :style="{opacity: isBoss ? 0.05 : 1 }">
        <el-row>
          <span>
            fen:  {{ currentFen !== '' ? currentFen : openFen }}
            <el-row>
              <el-button class="firstLine" type="primary" size="mini" @click="copyFen">复制</el-button>
              <el-button class="firstLine" type="info" size="mini" @click="importModal=true">导入</el-button>
              <el-button class="firstLine" type="warning" size="mini" @click="analyzeFen" :loading="analyzeFenLoading">分析</el-button>
              <el-tooltip class="item" effect="dark" content="分析当前局面所有合法的走法" placement="top">
                <el-button class="firstLine" type="danger" size="mini" @click="slowAnalyze" >全量分析</el-button>
              </el-tooltip>
              <el-button class="firstLine" type="danger" size="mini" @click="isBoss=!isBoss">老板键</el-button>
            </el-row>
          </span>
        </el-row>
        <!--历史记录-->
        <el-table :data="historyData" border stripe
                  highlight-current-row :height="200"
                  @cell-click="handleSelectMove" :span=16 :style="{opacity: isBoss ? 0.05 : 1 }">
          <el-table-column
              type="index"
              label="步数"
              width="50">
          </el-table-column>
          <el-table-column
              prop="white"
              label="白方"
          >
          </el-table-column>
          <el-table-column
              prop="black"
              label="黑方"
          >
          </el-table-column>
        </el-table>
        <el-row :span=16 :style="{opacity: isBoss ? 0.05 : 1 }">
          <el-tooltip class="item" effect="dark" content="翻转黑白朝向" placement="top">
            <el-button type="info" icon="el-icon-refresh" class="f-m-5" size="small" @click="reverseBoard"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="回到最开始" placement="top">
            <el-button type="primary"  round icon="el-icon-d-arrow-left" class="f-m-5" size="small" @click="jumpToBegin"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="后退一步" placement="top">
            <el-button type="primary" round icon="el-icon-arrow-left" class="f-m-5" size="small"  @click="jumpToBack" ></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="前进一步" placement="top">
            <el-button type="primary" round icon="el-icon-arrow-right" class="f-m-5" size="small" @click="jumpToNext"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="跳转到末尾" placement="top">
            <el-button type="primary" round icon="el-icon-d-arrow-right" class="f-m-5" size="small" @click="jumpToEnd"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="悔棋/撤回落子" placement="top">
            <el-button type="warning" icon="el-icon-refresh-left" class="f-m-5" size="small" @click="undo"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="新的棋局" placement="top">
            <el-button type="danger" icon="el-icon-document" class="f-m-5" size="small" @click="newModal=true"></el-button>
          </el-tooltip>
          <el-button type="danger" class="f-m-5" size="small" @click="deleteAllFen" v-if="isDev">删除全部棋步</el-button>
          <el-tooltip class="item" effect="dark" content="老板键" placement="top">
            <el-button type="danger" round icon="el-icon-s-platform" class="f-m-5" size="small"  @click="isBoss=!isBoss"></el-button>
          </el-tooltip>
        </el-row>
      </el-col>
    </el-row>
    <div style="margin-top: 20px">
      <br>
      <h5  style="margin-top: 20px">数据库/引擎分析：</h5>
      <!--    棋步列表-->
      <el-table :data="stepData" stripe :height="250" :span=16 :style="{opacity: isBoss ? 0.05 : 1}" style="margin-top: 20px">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left">
              <el-form-item label="更新时间:">
                <span>{{ props.row.createTime }}</span>
              </el-form-item>
              <el-form-item label="后续走法:">
                <el-row>
                  <span>{{ props.row.pv || '等待引擎分析' }}</span>
                </el-row>
              </el-form-item>
              <el-form-item label="分析后续走法:">
                <el-tooltip class="item" effect="dark" content="将当前棋步的后续走法全部分析" placement="top">
                  <el-button type="warning" size="mini" @click="saveAllAfterMove(props.row)" :disabled="!props.row.pv?.length">分析</el-button>
                </el-tooltip>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column
            prop="move"
            label="走法"
            width="70">
        </el-table-column>
        <el-table-column
            prop="name"
            label="局面名称"
            width="240">
        </el-table-column>
        <el-table-column
            prop="nameEn"
            label="局面英文名"
            width="280">
        </el-table-column>
        <el-table-column
            prop="value"
            label="引擎评分"
            width="130">
        </el-table-column>
        <el-table-column
            prop="dbValue"
            label="数据库评分"
            width="130">
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
        >
          <template slot-scope="scope">
            <el-button @click="chooseStep(scope.row)" type="primary" size="mini">选择</el-button>
            <el-button type="success" size="mini" @click="showImport(scope.row)">保存</el-button>
            <el-button type="danger" size="mini" @click="deleteFen(scope.row)" :disabled="!scope.row.dbValue" v-if="isDev">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!--    导入fen的对话框-->
    <el-dialog
        :visible.sync="importModal"
        title="导入fen"
        width="800px"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        >
      <p>fen:
        <el-input v-model="importFenText" style="width: 700px"></el-input>
      </p>
      <chessboard class="f-tac" v-if="importFenText!=null" :free="false" :fen="importFenText"/>
      <el-button @click="importModal = false" size="mini">取消</el-button>
      <el-button type="primary" @click="importFen" size="mini">确定</el-button>
    </el-dialog>
    <!--保存局面的对话框-->
    <el-dialog
        :visible.sync="saveModal"
        title="保存局面"
        width="80%" center
        :close-on-click-modal="false"
        :close-on-press-escape="false"
    >
      <el-row>
        <el-col :span="12">
          <h5>当前局面</h5>
          <chessboard class="f-m-r-5" :free="false" :fen="beforeFen"/>
        </el-col>
        <el-col :span="12">
          <h5>下一步</h5>
          <chessboard class="f-m-l-5" :free="false" :fen="afterFen"/>
        </el-col>
      </el-row>
      <p class="f-m-5">局面中文名:
        <el-input class="f-m-5" v-model="saveFenName" style="width: 300px"></el-input>
      </p>
      <p class="f-m-5">局面英文名:
        <el-input class="f-m-5" v-model="saveFenNameEn" style="width: 300px"></el-input>
      </p>
      <p class="f-m-5">局面评分: {{ saveValue }}</p>
      <p class="f-m-5">下一步走法: {{ saveMove }}</p>
      <el-button @click="saveModal=false" size="mini">取消</el-button>
      <el-button type="primary" @click="saveFen" size="mini">确定</el-button>
    </el-dialog>
    <!--新局面-->
    <el-dialog
        :visible.sync="newModal"
        title="新棋局"
        width="250px"
        >
      <p class="f-tac">是否开始新的棋局</p>
      <chessboard class="f-tac" v-if="importFenText!=null" :free="false" :fen="importFenText"/>
      <el-button @click="newModal=false" size="mini">取消</el-button>
      <el-button type="primary" @click="playNewGame" size="mini">确定</el-button>
    </el-dialog>
    <!--全量分析或者分析后续的结果-->
    <el-dialog
        :visible.sync="slowAnalyzeModal"
        title="分析结果"
        width="1000px"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
    >
      <el-table :data="slowAnalyzeData" border stripe  style="width: 100%"  height="400px"  @selection-change="handleSelectionChange">
        <el-table-column
            type="selection"
            width="55">
        </el-table-column>
        <el-table-column
            type="index"
            label="序号"
            width="50">
        </el-table-column>
        <el-table-column
            prop="fen"
            label="fen"
           >
        </el-table-column>
        <el-table-column
            prop="move"
            label="走法"
            width="70">
        </el-table-column>
        <el-table-column
            prop="hasData"
            label="是否入库"
            width="80">
        </el-table-column>
        <el-table-column
            prop="value"
            label="引擎评分"
            width="100">
        </el-table-column>
      </el-table>
      <el-button @click="slowAnalyzeModal=false" size="mini" :loading="slowAnalyzeLoading">取消</el-button>
      <el-button type="primary" @click="saveSlowResult" size="mini" :loading="slowAnalyzeLoading">保存</el-button>
    </el-dialog>
    <!--全量分析的配置框-->
    <el-dialog
        :visible.sync="slowAnalyzeConfigModal"
        title="全量分析"
        width="900px"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :show-close="false"
    >
      <h5>自动过滤已入库数据</h5>
      <el-table :data="slowAnalyzeData" border stripe  style="width: 100%"  height="400px"  @selection-change="handleSelectionChange">
        <el-table-column
            type="selection"
            width="55">
        </el-table-column>
        <el-table-column
            type="index"
            label="序号"
            width="50">
        </el-table-column>
        <el-table-column
            prop="fen"
            label="fen"
        >
        </el-table-column>
        <el-table-column
            prop="move"
            label="走法"
            width="70">
        </el-table-column>
        <el-table-column
            prop="hasData"
            label="是否入库"
            width="50">
        </el-table-column>
        <el-table-column
            prop="value"
            label="评分"
            width="100">
        </el-table-column>
      </el-table>
      <div class="f-m-5">
        <el-button @click="slowAnalyzeConfigModal=false" size="mini" :loading="slowAnalyzeLoading">取消</el-button>
        <el-button type="primary" @click="saveSlowResult" size="mini" :loading="slowAnalyzeLoading">保存</el-button>
        <el-checkbox v-model="filterBlunder" class="f-m-5">过滤错着和败着</el-checkbox>
      </div>

    </el-dialog>
  </div>
</template>

<script>

import * as utils from "@/lib/utils";
import {invoke} from "@/lib/utils";
import {clipboard} from "electron";
import Database from "@/lib/database";
import Chessmate from "@/lib/chessmate";
import Sqlite from "@/lib/sqlite";
import {chessboard} from "vue-chessboard";
import emitvue from "@/lib/emitvue";
import {getFenNameEN} from "@/lib/reptile";
import {DEFAULT_CONFIG, ECO} from "@/lib/constants";
import _ from "lodash";
import path from "path";

export default {
  name: "Analyze",
  // extends: chessboard,
  data() {
    return {
      appPath: null, //程序exe的目录
      isDev: false,
      isBoss: false,
      currentFen: '',
      openFen: utils.newGame,
      ifFree: false,//随意走子
      boardColor: 'white',//棋盘朝向
      activeName: 'analyze',
      settingForm: {
        dbPath: '',
        enginePath: '',
        analyzeSpeed: '快速',
        mistakeThreshold: 0.5,
        blunderThreshold: 1
      },
      importModal: false,
      importFenText: null,
      analyzeFenLoading: false,
      stepData: [],
      lessonFen: '',
      promoteModal: false, // 升变对话框,
      promoteText: '后',

      slowAnalyzeLoading: false, //全量分析

      // 保存相关
      saveModal: false, // 保存对话框
      beforeFen: '',
      afterFen: '', // 保存后的局面
      saveFenName: '', // 中文
      saveFenNameEn: '', // 英文
      saveValue: '',
      saveMove: '',


      // 历史记录
      history: [],
      historyData: [], // 转换过的历史记录

      newModal: false, // 是否开始新的棋局
      currentStepNum: 0, //目前的棋步

      // 全量分析和分析结果的确认框
      slowAnalyzeModal: false,
      slowAnalyzeData: [],
      // 被选择要入库的数据
      selectedSlowData: [],
      slowAnalyzeConfigModal: false,

      // 是否过滤blunder
      filterBlunder: true,
    }
  },
  methods: {
    // 每次移动棋子会触发
    async getInfo(data) {
      const fen = data.fen
      this.stepData = await this.getFenFromDB(fen)
      if (!data.history?.length) return
      this.currentFen = data.fen
      this.stepData = []
      this.history.push({move: data.history[data.history.length - 1], fen: data.fen})
      this.parseMove2History()
      this.currentStepNum++
      console.log("getInfo", this.currentStepNum)
    },
    async getFenFromDB(fen) {
      const res =  await Database.searchFen(fen)
      for (const item of res) {
        item.dbValue = item.value
        delete item.value
      }
      return res
    },

    // 升变
    promote() {
      if (confirm("是否升变为后？")) {
        return 'q'
      } else {
        if (confirm("是否升变为车？")) {
          return 'r'
        } else {
          if (confirm("是否升变为马？")) {
            return 'n'
          } else {
            if (confirm("是否升变为象？")) {
              return 'b'
            }
          }
        }
      }
      return 'q'
    },

    copyFen() {
      clipboard.writeText(this.currentFen)
      this.$notify({duration: 1000, title: '通知', message: "已经复制到剪切板", type: 'success'})
    },
    importFen() {
      this.importModal = false
      this.currentFen = this.importFenText
      this.openFen = this.importFenText
      this.importFenText = null
    },
    async analyzeFen() {
      if (this.settingForm.enginePath === '') return this.$notify({duration: 1000, title: '通知', message: "请先配置引擎路口", type: 'warning'})
      this.analyzeFenLoading = true
      const data = await Chessmate.analyze(this.currentFen === '' ? this.openFen : this.currentFen)
      this.analyzeFenLoading = false
      const result = Chessmate.parseAnalyze(this.currentFen === '' ? this.openFen : this.currentFen, data)
      const dbData = await this.getFenFromDB(this.currentFen)
      const dbDataMap = {}
      for (const item of dbData) {
        dbDataMap[item.move] = item
      }
      for (const item of result.moveList) {
        if (dbDataMap[item.move]) {
          item.dbValue = dbDataMap[item.move]?.dbValue || ''
          item.nameEn = dbDataMap[item.move]?.nameEn || ''
          item.name = dbDataMap[item.move]?.name || ''
          item.createTime = dbDataMap[item.move]?.createTime || ''
          // 需要把pv里的uci棋步转为正常的棋步
          const newPv = []
          const pv = item.pv
          let tempFen = this.currentFen
          for (const move of pv) {
            newPv.push(Chessmate.parseUCIMove(tempFen, move))
            tempFen = Chessmate.move(tempFen, move)
          }
          item.pv = newPv
        }
      }
      this.stepData = result.moveList

    },
    async showImport(data) {
      this.saveModal = true
      this.saveValue = data.value || data.dbValue || ''
      this.saveMove = data.move
      this.saveFenNameEn = data.nameEn || ''
      this.saveFenName = data.name || ''
      // 如果有数据库数据，那就读取数据库的数据，否则可以从Lichess爬取
      if ((!this.saveFenName || this.saveFenName === '') && (!this.saveFenNameEn || this.saveFenNameEn === '')) {
        const lichessEcoData = await getFenNameEN(this.currentFen, data.uciMove)
        this.saveFenNameEn = lichessEcoData.nameEn
        this.saveFenName = ECO[lichessEcoData.eco]?.name
      }
      await utils.sleep(200)
      this.beforeFen = Chessmate.move(this.currentFen, null)
      this.afterFen = Chessmate.move(this.currentFen, data.move)
    },
    // 保存fen至数据库
    async saveFen() {
      this.saveModal = false
      const data = {
        fen: this.beforeFen,
        value: this.saveValue,
        move: this.saveMove,
        createTime: utils.getCurrentTime(),
        name: this.saveFenName,
        nameEn: this.saveFenNameEn,
      }

      await Database.saveFen(data)
      // this.stepData = await this.getFenFromDB(this.beforeFen)
      this.$notify({duration: 1000, title: '通知', message: "保存成功", type: 'success'})
      this.beforeFen = ''
      this.saveValue = ''
      this.saveMove = ''
      this.saveFenName = ''
      this.saveFenNameEn = ''
    },
    // 全量分析
    async slowAnalyze() {
      const moves = Chessmate.getInvalidMoveList(this.currentFen)
      console.log("moves", moves)
      this.slowAnalyzeData = []
      const needAnalyzeMove = []
      
      for (const item of moves) {
        const dbData = await Database.searchMove(this.currentFen, item)
        if (dbData.length > 0) {
          dbData[0].hasData = '是'
          this.slowAnalyzeData.push(dbData[0])
        } else {
          needAnalyzeMove.push({move: item, fen: this.currentFen})
        }
      }

      this.slowAnalyzeConfigModal = true
      this.slowAnalyzeLoading = true
      for (const item of needAnalyzeMove) {
        const nextFen = Chessmate.move(this.currentFen, item.move)
        const res = await Chessmate.analyzeCurrentFenValue(nextFen)
        // 分析的是如果一方选择了当前的棋步，另一方做出的最优解，所以需要取上一步的数据
        res.fen = this.currentFen
        res.move = item.move
        res.uciMove = Chessmate.getUCIMove(this.currentFen, item.move)
        res.hasData = '否'
        this.slowAnalyzeData.push(res)
      }
      this.slowAnalyzeData = _.sortBy(this.slowAnalyzeData, 'value')
      let bestValue = 0
      if (Chessmate.isWhite(this.currentFen)) {
        bestValue = this.slowAnalyzeData[this.slowAnalyzeData.length - 1].value
      } else {
        bestValue = this.slowAnalyzeData[0].value
      }
      for (const item of this.slowAnalyzeData) {
        item.rowValue = item.value  // 排序用
        item.value = Chessmate.judgeValue(item.value, bestValue)
        item.valueText = item.value // 入库用 - -
      }
      if (Chessmate.isWhite(this.currentFen)) {
        this.slowAnalyzeData = _.orderBy(this.slowAnalyzeData,['rowValue'], ['desc'])
      } else {
        this.slowAnalyzeData = _.orderBy(this.slowAnalyzeData,['rowValue'], ['asc'])
      }
      this.slowAnalyzeLoading = false
    },
    // 选择这步棋
    chooseStep(data) {
      this.currentFen = Chessmate.move(this.currentFen !== '' ? this.currentFen : this.openFen, data.move)
      this.stepData = []
      this.history.push({move: data.move, fen: data.fen})
      this.currentStepNum++
      this.parseMove2History()
      console.log("this.currentStepNum", this.currentStepNum)
    },
    async getSetting() {
      let config = await invoke('get', {name: 'setting', type: 'database'})
      if (!config) {
        await invoke('set', JSON.stringify({name: 'setting', type: 'database', dbPath: '', enginePath: ''}))
      } else {
        // if (!utils.existValue(config.defaultValue) || config.defaultValue === true) {
        //   config = DEFAULT_CONFIG
        //   config.dbPath = path.join(this.appPath, config.dbPath)
        //   config.enginePath = path.join(this.appPath, config.enginePath)
        // }
        this.settingForm.dbPath = config.dbPath
        this.settingForm.enginePath = config.enginePath
        console.log("this.settingForm.dbPath", this.settingForm.dbPath)
        await Sqlite.connect(this.settingForm.dbPath)
        const chessConfig = {
          path: config.enginePath,
          analyzeSpeed: config.analyzeSpeed,
          blunderThreshold: config.blunderThreshold,
          mistakeThreshold: config.mistakeThreshold,
        }

        await Chessmate.init(chessConfig)
      }
    },
    // 从数据库删除一个局面
    async deleteFen(data) {
      const fen = data.fen
      const move = data.move
      await Database.deleteFen(fen, move)
      this.$notify({duration: 1000, title: '通知', message: "删除成功", type: 'success'})
      this.stepData = await this.getFenFromDB(fen)
    },
    handleSelectMove(row, column, cell, event) {
      console.log("column",column);
      console.log("row",row);
    },
    // 将走法解析成历史记录
    parseMove2History() {
      this.historyData = [];
      let black = [];
      let white = [];
      // 先把黑白分开
      for (let i = 0; i < this.history.length; i++) {
        if (i % 2 === 0) {
          white.push({move: this.history[i].move, fen: this.history[i].fen});
        } else {
          black.push({move: this.history[i].move, fen: this.history[i].fen})
        }
      }
      for (let i = 0; i < white.length; i++) {
        let list = {
          index: i + 1,
          white: white[i].move,
          whiteFen: white[i].fen,
          // 白棋肯定会有 黑棋有可能还没开始下
          black: black[i]?.move || '',
          blackFen: black[i]?.fen || null,
        }
        this.historyData.push(list);
      }
    },
    reverseBoard() {
      this.boardColor = this.boardColor === 'white' ? 'black' : 'white';
    },
    // 开始新棋局
    playNewGame() {
      this.newModal = false
      this.stepData = []
      this.historyData = []
      this.history = []
      this.currentFen = utils.newGame
      this.currentStepNum = 0
      this.openFen = utils.newGame
      this.$forceUpdate()
    },
    // 几个跳转的按钮
    jumpToBegin() {
      this.currentFen = this.openFen
      this.currentStepNum = 0
    },
    jumpToBack() {
      this.currentStepNum--
      console.log("jumpToBack this.currentStepNum", this.currentStepNum)
      if (this.currentStepNum < 1 ) {
        this.jumpToBegin()
      }
      else {
        this.currentFen = this.history[this.currentStepNum - 1].fen
      }
    },
    jumpToNext() {
      this.currentStepNum++
      if (this.currentStepNum > this.history.length) {
        // 没必要做任何操作
        this.$notify({duration: 1000, title: '通知', message: "已经来到了棋局末尾", type: 'success'})
      }
      else {
        this.currentFen = this.history[this.currentStepNum - 1].fen
      }
    },
    jumpToEnd() {
      if (this.history.length) {
        this.currentFen = this.history[this.history.length-1].fen
      }
      this.currentStepNum = this.history.length
    },
    // 悔棋
    undo() {
      this.history.pop()
      this.jumpToEnd()
      // 先跳转到末尾
      if (this.currentStepNum > 0) this.currentStepNum--
      // 防止悔棋没法悔第一步
      if (this.history.length === 0) this.currentFen = this.openFen
      this.parseMove2History()
    },
    // 入库后续走法
    async saveAllAfterMove(data) {
      const result = []
      const loading = this.$loading({text: '正在分析'})
      const pv = data.pv
      let nextFen = this.currentFen
      for (const singleMove of pv) {
        const parsedMove = Chessmate.parseUCIMove(nextFen, singleMove)
        const checkDb = await Database.existMove(nextFen, parsedMove)
        const res = await Chessmate.analyzeCurrentFenValue(nextFen)
        res.fen = nextFen
        res.hasData = checkDb === true ? '是' : '否'
        // 因为引擎的结果是下一步棋的 现在分析的是当前局面
        res.move = parsedMove
        result.push(res)
        nextFen = Chessmate.move(nextFen, singleMove)

      }
      loading.close()
      this.slowAnalyzeData = result
      this.slowAnalyzeModal = true
    },
    handleSelectionChange(val) {
      this.selectedSlowData = val
    },
    // 将全量分析的数据保存入库
    async saveSlowResult() {
      this.slowAnalyzeLoading = true
      for (const item of this.selectedSlowData) {
        const {fen, move, valueText, uciMove, hasData} = item
        if (hasData === '是') continue
        if (this.filterBlunder) {
          if (String(valueText).indexOf('mistake') !== -1 || String(valueText).indexOf('blunder') !==-1 ) continue
        }
        const lichessData = await getFenNameEN(fen, uciMove)
        const data = {
          fen,
          value: valueText,
          move,
          createTime: utils.getCurrentTime(),
          name: ECO[lichessData?.eco]?.name || '',
          nameEn: lichessData?.nameEn || '',
        }
        await Database.saveFen(data, {updataName: false})
      }
      this.slowAnalyzeLoading = false
      this.slowAnalyzeModal = false
      this.slowAnalyzeConfigModal = false
      this.$notify({duration: 1000, title: '通知', message: "保存成功", type: 'success'})
      this.stepData = await this.getFenFromDB(this.currentFen)

    },
    async deleteAllFen () {
      if (confirm("是否删除当前局面全部数据")) {
        await Database.deleteFen(this.currentFen, null)
        this.stepData = await this.getFenFromDB(this.currentFen)
      }
    },
  },
  async mounted() {
    if (location.protocol.indexOf('http') !== -1) {
      this.isDev = true
    }
    const isHome = await invoke('isHome', null)
    if (isHome === 'true' || isHome === true) {

    } else {
      this.isBoss = this.isDev
    }
    this.appPath = await invoke('getCurrentPath', null)
    await this.getSetting()
    emitvue.$on('refreshSetting', async () => {
      await this.getSetting()
    })
    this.currentFen = this.openFen
    emitvue.$on('analyzeActive', async ()=> {
      this.currentFen = this.openFen
      this.dbData = await Database.searchFen(this.currentFen)
      this.reverseBoard()
      this.reverseBoard()
    })
    const currentPath = process.cwd()
    console.log("currentPath", currentPath)
  },
  components: {
    chessboard,
  },
}
</script>


<style scoped>
.firstLine {
  display: inline-block;
  margin: 5px;
}
</style>